package com.sinosoft.hydra.um.domain.model;

import cn.com.sinux.spring.utils.BeanUtils;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ImportTemplate implements Serializable {

    //导入的配置项
    private String keyCode;

    //导入的标题
    private String title;

    //导入的配置项附件
    private String attachment;

    //导入的配置项类名
    private String domainName;

    //导入的配置项属性名
    private String domainProperty;

    //导入的对象涉及枚举字段
    private String domainEnum;

    //导入对象持久关系，例如 com.wicom.is.PersService.workMeth
    private String persistenceMethod;

    //出现一个出错即全部回滚
    private boolean errorStop;

    private String desPath;

    public String getDesPath() {
        return desPath;
    }

    public void setDesPath(String desPath) {
        this.desPath = desPath;
    }

    public boolean isErrorStop() {
        return errorStop;
    }

    public void setErrorStop(boolean errorStop) {
        this.errorStop = errorStop;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    private List<ImportTemplate> importTemplates = new ArrayList<ImportTemplate>();

    public List<ImportTemplate> getImportTemplates() {
        return importTemplates;
    }

    private static ImportTemplate factory;

    public static ImportTemplate createFactory(List<ImportTemplate> importTemplates) {
        if (factory == null) {
            factory = new ImportTemplate();
            factory.getImportTemplates().addAll(importTemplates);
        }
        return factory;
    }

    public static void destroy() {
        factory = null;
    }

    public static ImportTemplate valueOf(String keyCode) {
        if (StringUtils.isNotBlank(keyCode)) {
            for (ImportTemplate importTemplate : factory.getImportTemplates()) {
                if (keyCode.equals(importTemplate.getKeyCode())) {
                    ImportTemplate dd = new ImportTemplate();
                    BeanUtils.copyProperties(importTemplate, dd);
                    return dd;
                }
            }
        }
        return null;
    }

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database table T_IMPORT_TEMPLATE
     *
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    private static final long serialVersionUID = 1L;

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column T_IMPORT_TEMPLATE.KEY_CODE
     *
     * @return the value of T_IMPORT_TEMPLATE.KEY_CODE
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public String getKeyCode() {
        return keyCode;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column T_IMPORT_TEMPLATE.KEY_CODE
     *
     * @param keyCode the value for T_IMPORT_TEMPLATE.KEY_CODE
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public void setKeyCode(String keyCode) {
        this.keyCode = keyCode;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column T_IMPORT_TEMPLATE.ATTACHMENT
     *
     * @return the value of T_IMPORT_TEMPLATE.ATTACHMENT
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public String getAttachment() {
        return attachment;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column T_IMPORT_TEMPLATE.ATTACHMENT
     *
     * @param attachment the value for T_IMPORT_TEMPLATE.ATTACHMENT
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public void setAttachment(String attachment) {
        this.attachment = attachment;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column T_IMPORT_TEMPLATE.DOMAIN_NAME
     *
     * @return the value of T_IMPORT_TEMPLATE.DOMAIN_NAME
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public String getDomainName() {
        return domainName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column T_IMPORT_TEMPLATE.DOMAIN_NAME
     *
     * @param domainName the value for T_IMPORT_TEMPLATE.DOMAIN_NAME
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column T_IMPORT_TEMPLATE.DOMAIN_PROPERTY
     *
     * @return the value of T_IMPORT_TEMPLATE.DOMAIN_PROPERTY
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public String getDomainProperty() {
        return domainProperty;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column T_IMPORT_TEMPLATE.DOMAIN_PROPERTY
     *
     * @param domainProperty the value for T_IMPORT_TEMPLATE.DOMAIN_PROPERTY
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public void setDomainProperty(String domainProperty) {
        this.domainProperty = domainProperty;
    }

    public String getDomainEnum() {
        return domainEnum;
    }

    public void setDomainEnum(String domainEnum) {
        this.domainEnum = domainEnum;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column T_IMPORT_TEMPLATE.PERSISTENCE_METHOD
     *
     * @return the value of T_IMPORT_TEMPLATE.PERSISTENCE_METHOD
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public String getPersistenceMethod() {
        return persistenceMethod;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column T_IMPORT_TEMPLATE.PERSISTENCE_METHOD
     *
     * @param persistenceMethod the value for T_IMPORT_TEMPLATE.PERSISTENCE_METHOD
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */
    public void setPersistenceMethod(String persistenceMethod) {
        this.persistenceMethod = persistenceMethod;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table T_IMPORT_TEMPLATE
     *
     * @mbggenerated Fri Oct 09 10:00:39 CST 2015
     */

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", keyCode=").append(keyCode);
        sb.append(", attachment=").append(attachment);
        sb.append(", domainName=").append(domainName);
        sb.append(", domainProperty=").append(domainProperty);
        sb.append(", domainEnum=").append(domainEnum);
        sb.append(", persistenceMethod=").append(persistenceMethod);
        sb.append("]");
        return sb.toString();
    }
}